<template>
    <div class="page-category">
        <van-nav-bar
            :title="$t('m.Category')"
            left-arrow
            @click-left="onClickLeftCategoty"
            right-text="Next"
            @click-right="$router.push({path:'/sub-category'})"
        />
        <van-list>
            <!--job 部分 差部分校验没有做， service没有做-->
            <van-cell v-for="item in categoryJson" v-if="!(item.id ==349)" :key="item.id" :title="item.name + ''" @click="onSelectCategory(item)"/>
        </van-list>
        <div style="padding:40px;"></div>
        <footer-bar ref="footer" footerBar=""></footer-bar>
    </div>
</template>

<script>

    // 英文json
    import categoryJson from '../static/json/category'

    // 缅甸文json
    import mm_categoryJson from '../static/mmJson/category'

    // 缅甸unicode
    import mmu_categoryJson from '../static/mmUnicodeJson/category'
    import FooterBar from '@/components/FooterBar'


    function setState(store) {
    }

    export default {
        name: 'category',
        middleware: ['login'],
        metaInfo: {
            title: 'category',
            titleTemplate: '%s',
            meta: [
                {name: 'keywords', content: 'lavas PWA'},
                {name: 'description', content: '基于 Vue 的 PWA 解决方案，帮助开发者快速搭建 PWA 应用，解决接入 PWA 各种问题'}
            ]
        },
        components: {
            FooterBar
        },
        async asyncData({store, route}) {
            setState(store);
        },
        data() {
            return {
                // categoryJson: categoryJson,
                categoryId: ''
            };
        },
        computed: {
            categoryJson() {
                if (this.$store.state.store.localLang == 'MM') {
                    return mm_categoryJson
                } else if (this.$store.state.store.localLang == 'MMU') {
                    return mmu_categoryJson
                } else {
                    return categoryJson
                }
            },
        },
        methods: {
            onClickLeftCategoty() {
                this.$router.push({path: '/'})
            },
            onSelectCategory(item) {
                if (!item.children.length > 0) {
                    this.$router.push({
                        path: '/sell',
                        query: {
                            id: item.id,
                            categoryText: item.name
                        }
                    })
                } else {

                    // 如果id为property 则跳转下载页面
                    if (item.id == 371) {
                        this.$router.push({path: '/download-property'})
                        return;
                    }

                    this.$router.push({
                        path: '/sub-category',
                        query: {
                            id: item.id,
                            categoryText: item.name
                        }
                    })
                }
            },
        },
        mounted() {
            // sotre 作为全局的状态管理 慎重修改
            // 取值方式
            // console.log(this.$store.state.store.localLang, 'localLang')
            // this.$store.commit('store/updateLang', 'US')
            // console.log(this.$store.state.store.localLang, 'localLang')
        }
    };
</script>

<style scoped>

</style>

